<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>老黄历</title>
<meta name="keywords" content="老黄历,lunar,阳历,阴历,公历,农历" />
<meta name="description" content="lunar是一个无依赖的支持阳历和阴历的日历工具库。" />
<meta name="author" content="6tail" />
<link rel="stylesheet" href="common.css">
<link rel="stylesheet" href="highlight.min.css">
<link rel="stylesheet" href="markdown.css">
<link rel="stylesheet" href="page.css">
<style type="text/css">
.line{
  margin:20px;
}
.line input{
  padding:5px;
}
.huangli{}
.huangli div{
  margin-top:20px;
}
.markdown-body td a{
  margin-left:2px;
  color:#007CD5;
  padding:0 6px;
  -webkit-border-radius:50%;
 -moz-border-radius:50%;
 -ms-border-radius:50%;
 -o-border-radius:50%;
 border-radius:50%;
}
.markdown-body td a:hover{
  background:#007CD5;
  color:#fff;
  text-decoration:none;
}
</style>
</head>
<body>
<div class="article">

<textarea class="md">

## 老黄历

请填写公历（阳历）时间，默认为当日：
</textarea>
<div class="line"><input id="year" type="text"> 年 <input id="month" type="text"> 月 <input id="day" type="text"> 日</div>

<div class="huangli">
  <table>
    <tbody>
      <tr>
        <td width="120">公历</td>
        <td id="c"></td>
      </tr>
      <tr>
        <td>农历</td>
        <td id="b"></td>
      </tr>
      <tr>
        <td>佛历</td>
        <td id="foto"></td>
      </tr>
      <tr>
        <td>道历</td>
        <td id="tao"></td>
      </tr>
      <tr>
        <td>年</td>
        <td id="a"></td>
      </tr>
      <tr>
        <td>月</td>
        <td id="a1"></td>
      </tr>
      <tr>
        <td>日</td>
        <td id="a2"></td>
      </tr>
      <tr>
        <td>空亡</td>
        <td id="xun"></td>
      </tr>
        <td>日禄</td>
        <td id="rilu"></td>
      </tr>
      <tr>
        <td>纪念节日</td>
        <td id="x"></td>
      </tr>
      <tr>
        <td>儒略日</td>
        <td id="a3"></td>
      </tr>
      <tr>
        <td>上一节气</td>
        <td id="p"></td>
      </tr>
      <tr>
        <td>下一节气</td>
        <td id="n"></td>
      </tr>
      <tr>
        <td>数九</td>
        <td id="shuJiu"></td>
      </tr>
      <tr>
        <td>三伏</td>
        <td id="fu"></td>
      </tr>
      <tr>
        <td>月名</td>
        <td id="m"></td>
      </tr>
      <tr>
        <td>月相</td>
        <td id="yuexiang"></td>
      </tr>
      <tr>
        <td>六曜</td>
        <td id="liuyao"></td>
      </tr>      
      <tr>
        <td>物候</td>
        <td id="wuhou"></td>
      </tr>
      <tr>
        <td>治水</td>
        <td id="zhishui"></td>
      </tr>
      <tr>
        <td>分饼</td>
        <td id="fenbing"></td>
      </tr>
      <tr>
        <td>耕田</td>
        <td id="gengtian"></td>
      </tr>
      <tr>
        <td>得金</td>
        <td id="dejin"></td>
      </tr>
      <tr>
        <td>彭祖百忌</td>
        <td id="d"></td>
      </tr>
      <tr>
        <td>当日宜忌</td>
        <td id="yj"></td>
      </tr>
      <tr>
        <td>吉神</td>
        <td id="js"></td>
      </tr>
      <tr>
        <td>凶煞</td>
        <td id="xs"></td>
      </tr>
      <tr>
        <td>相冲</td>
        <td id="e"></td>
      </tr>
      <tr>
        <td>相煞</td>
        <td id="fd"></td>
      </tr>
      <tr>
        <td>贵神方位</td>
        <td id="h"></td>
      </tr>
      <tr>
        <td>喜神方位</td>
        <td id="i"></td>
      </tr>
      <tr>
        <td>福神方位</td>
        <td id="i1"></td>
      </tr>
      <tr>
        <td>财神方位</td>
        <td id="i2"></td>
      </tr>
      <tr>
        <td>当月胎神</td>
        <td id="i3"></td>
      </tr>
      <tr>
        <td>当日胎神</td>
        <td id="i4"></td>
      </tr>
      <tr>
        <td>太岁方位</td>
        <td id="i5"></td>
      </tr>
      <tr>
        <td>十二值星</td>
        <td id="j"></td>
      </tr>
      <tr>
        <td>十二天神</td>
        <td id="k"></td>
      </tr>
      <tr>
        <td>星宿</td>
        <td id="g"></td>
      </tr>
      <tr>
        <td>星宿歌诀</td>
        <td id="g1"></td>
      </tr>	  
      <tr>
        <td>三元九运</td>
        <td id="syjy"></td>
      </tr>
      <tr>
        <td>当年九星</td>
        <td id="jiuxingy"></td>
      </tr>
      <tr>
        <td>年星歌诀</td>
        <td id="jiuxing-songy"></td>
      </tr>      
      <tr>
        <td>当月九星</td>
        <td id="jiuxingm"></td>
      </tr>
      <tr>
        <td>月星歌诀</td>
        <td id="jiuxing-songm"></td>
      </tr>   
      <tr>
        <td>当日九星</td>
        <td id="jiuxing"></td>
      </tr>
      <tr>
        <td>日星歌诀</td>
        <td id="jiuxing-song"></td> 
      </tr>
    </tbody>
  </table>
  
  <div id="times"></div>
</div>

<div style="color:#999;">说明：双手指缩放屏幕，调整字体大小；左右滑动屏幕查看各个时辰内容。</div>

</div>
<script src="jquery.min.js"></script>
<script src="highlight.min.js"></script>
<script src="marked.min.js"></script>
<script src="common.js"></script>
<script src="lunar.js"></script>
<script>
mdr('.md');
</script>
<script>
(function(){
  var today = Solar.fromDate(new Date());
  $('#year').val(today.getYear());
  $('#month').val(today.getMonth());
  $('#day').val(today.getDay());
  
  var throttle = function(fn,delay,atleast){
    var timer = null;
    var previous = null;
    return function(){
      var now = +new Date();
      if(!previous) previous = now;
      if(atleast && now - previous > atleast){
        fn();
        previous = now;
        clearTimeout(timer);
      } else {
        clearTimeout(timer);
        timer = setTimeout(function(){
          fn();
          previous = null;
        }, delay);
      }
    }
  };
  
  var onChange = throttle(function(){
    compute();
  },20,50);
  
  // 生成时辰表
  var renderTime = function(year,month,day){
    var l = [];
    // 00:00:00作为早子时
    l.push(Solar.fromYmdHms(year,month,day,0,0,0).getLunar());
    // 从01:00:00、03:00:00直到23:00:00(晚子时)遍历12个时辰
    for(var i=0;i<12;i++){
      l.push(Solar.fromYmdHms(year,month,day,(i+1)*2-1,0,0).getLunar());
    }
    var s = '<table><tbody>';
      var YinYang = {
      '甲':'阳',
      '丙':'阳',
      '戊':'阳',
      '庚':'阳',
      '壬':'阳',
      
      '子':'阳',
      '寅':'阳',
      '辰':'阳',
      '午':'阳',
      '申':'阳',
      '戌':'阳',
      
      '乙':'阴',
      '丁':'阴',
      '己':'阴',
      '辛':'阴',
      '癸':'阴',
      
      '丑':'阴',
      '卯':'阴',
      '巳':'阴',
      '未':'阴',
      '酉':'阴',
      '亥':'阴'
    };     
    s += '<tr><td width="9%">时辰</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td width="7%">'+l[i].getTimeInGanZhi()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>时刻</td><td>0:00-0:59</td>';
    for(var i=0;i<12;i++){
      s += '<td>'+((i+1)*2-1)+':00-'+((i+1)*2-(i<11?0:1))+':59'+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>生肖</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeShengXiao()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>阴阳</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+YinYang[l[i].getTimeGan()]+YinYang[l[i].getTimeZhi()]+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>五行</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+LunarUtil.WU_XING_GAN[l[i].getTimeGan()]+LunarUtil.WU_XING_ZHI[l[i].getTimeZhi()]+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>纳音</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeNaYin()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>相冲</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeChongDesc()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>相煞</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeSha()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>天神</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeTianShen()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>黑黄</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeTianShenType()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>吉凶</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeTianShenLuck()+'</td>';
    }
    s += '</tr>';

    s += '<tr><td>所宜</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeYi().join(' ')+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>所忌</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeJi().join(' ')+'</td>';
    }
    s += '</tr>';

    s += '<tr><td>财位</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimePositionCaiDesc()+l[i].getTimePositionCai()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>福位</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimePositionFuDesc()+l[i].getTimePositionFu()+'</td>';
    }
    s += '</tr>';    

    s += '<tr><td>阳贵</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimePositionYangGuiDesc()+l[i].getTimePositionYangGui()+'</td>';
    }
    s += '</tr>';
    
    s += '<tr><td>阴贵</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimePositionYinGuiDesc()+l[i].getTimePositionYinGui()+'</td>';
    }
    s += '</tr>';    

    s += '<tr><td>喜位</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimePositionXiDesc()+l[i].getTimePositionXi()+'</td>';
    }
    s += '</tr>';  

    s += '<tr><td>九星</td>';
    for(var i=0,j=l.length;i<j;i++){
      s += '<td>'+l[i].getTimeNineStar()+'</td>';
    }
    s += '</tr>';  
    
    s += '</tbody></table>';
    $('#times').html(s);
  };

  var compute = function(){
    try{
      var year = $('#year').val();
      var month = $('#month').val();
      var day = $('#day').val();
      if(year<1||year>9999){
        return;
      }
      if(month<1||month>12){
        return;
      }
      if(day<1||day>31){
        return;
      }
      year = parseInt(year,10);
      month = parseInt(month,10);
      day = parseInt(day,10);
      var s = Solar.fromYmd(year,month,day);
      var h = HolidayUtil.getHoliday(year, month, day);
      var d = s.getLunar();
      var foto = d.getFoto();
      var tao = d.getTao();
      $('#foto').html(foto.getYearInChinese()+'年 '+foto.getMonthInChinese()+'月 '+foto.getDayInChinese());
      $('#tao').html(tao.getYearInChinese()+'年 '+tao.getMonthInChinese()+'月 '+tao.getDayInChinese());	  
      var YinYang = {
      '甲':'阳',
      '丙':'阳',
      '戊':'阳',
      '庚':'阳',
      '壬':'阳',
      
      '子':'阳',
      '寅':'阳',
      '辰':'阳',
      '午':'阳',
      '申':'阳',
      '戌':'阳',
      
      '乙':'阴',
      '丁':'阴',
      '己':'阴',
      '辛':'阴',
      '癸':'阴',
      
      '丑':'阴',
      '卯':'阴',
      '巳':'阴',
      '未':'阴',
      '酉':'阴',
      '亥':'阴'
    };      
      $('#yuexiang').html(d.getYueXiang());
      $('#a').html(d.getYearInGanZhi()+d.getYearShengXiao()+' '+d.getYearNaYin()+' '+LunarUtil.WU_XING_GAN[d.getYearGan()]+LunarUtil.WU_XING_ZHI[d.getYearZhi()]+' '+ YinYang[d.getYearGan()] + YinYang[d.getYearZhi()]);
      $('#a1').html(d.getMonthInGanZhi()+d.getMonthShengXiao()+' '+d.getMonthNaYin()+' '+LunarUtil.WU_XING_GAN[d.getMonthGan()]+LunarUtil.WU_XING_ZHI[d.getMonthZhi()]+' '+ YinYang[d.getMonthGan()] + YinYang[d.getMonthZhi()]);
      $('#a2').html(d.getDayInGanZhi()+d.getDayShengXiao()+' '+d.getDayNaYin()+' '+LunarUtil.WU_XING_GAN[d.getDayGan()]+LunarUtil.WU_XING_ZHI[d.getDayZhi()]+' '+ YinYang[d.getDayGan()] + YinYang[d.getDayZhi()]);
      $('#a3').html(s.getJulianDay());
      $('#b').html(d.getYearInChinese()+'年 '+d.getMonthInChinese()+'月 '+d.getDayInChinese());
      $('#c').html(s.getYear()+'年 '+s.getMonth()+'月 '+s.getDay()+'日 星期'+s.getWeekInChinese()+'   '+ s.getXingZuo() +'座');
      $('#m').html(d.getSeason());
      $('#d').html(d.getPengZuGan()+'；'+d.getPengZuZhi());
      $('#yj').html('<span style="color:green">宜</span>：'+d.getDayYi().join(' ')+' <span style="color:red">忌</span>：'+d.getDayJi().join(' '));
      $('#e').html('('+d.getDayInGanZhi()+')'+d.getDayShengXiao()+' <span style="color:red">冲</span> '+d.getChongDesc());
      $('#js').html(d.getDayJiShen().join(' '));
      $('#xs').html(d.getDayXiongSha().join(' '));
      $('#f').html(d.getSha());
      $('#fd').html(d.getDaySha()+'方(凶)'+' ' +'(忌穿墙凿井、搬迁移徙、修建营造)');      
      $('#g').html(d.getGong()+'方'+d.getXiu()+'(二十八宿)'+d.getZheng()+'(七政)'+d.getAnimal()+'(28种动物)'+' ('+d.getXiuLuck()+')');
      $('#g1').html(d.getXiuSong());
      $('#h').html('阳贵神：'+d.getPositionYangGuiDesc()+d.getDayPositionYangGui()+' ；阴贵神：'+d.getPositionYinGuiDesc()+d.getDayPositionYinGui());
      $('#i').html(d.getPositionXiDesc()+d.getDayPositionXi());
      $('#i1').html(d.getPositionFuDesc()+d.getDayPositionFu());
      $('#i2').html(d.getPositionCaiDesc()+d.getDayPositionCai());
      $('#i3').html(d.getMonthPositionTai()+' ' +'(忌动土、移床、敲打及钻洞等)');
      $('#i4').html(d.getDayPositionTai());
      $('#i5').html(d.getDayPositionTaiSuiDesc());
	  
      var fs = [];
      var f = d.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = d.getOtherFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = s.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = s.getOtherFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = foto.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      f = tao.getFestivals();
      if (f) {
        for (var i=0,j=f.length;i<j;i++){
          fs.push(f[i]);
        }
      }
      if (h) {
        fs.push(h.getName()+(h.isWork()?'调休':'放假'));
      }
      $('#x').html(fs.join('、'));
      $('#j').html(d.getZhiXing());
      $('#k').html(d.getDayTianShen()+'('+d.getDayTianShenType()+') '+ d.getDayTianShenLuck());
	  
      var p = d.getPrevJieQi(),n = d.getNextJieQi();
      $('#p').html(p.getName()+' '+p.getSolar().toYmdHms()+' 星期'+p.getSolar().getWeekInChinese());
      $('#n').html(n.getName()+' '+n.getSolar().toYmdHms()+' 星期'+n.getSolar().getWeekInChinese());
  
      var jiuxing = d.getDayNineStar();
      var jiuxingy = d.getYearNineStar();
      var jiuxingm = d.getMonthNineStar();
      var jiuxingt = d.getTimeNineStar();
      $('#jiuxing').html(jiuxing.toFullString());
      $('#jiuxingy').html(jiuxingy.toFullString());      
      $('#jiuxingm').html(jiuxingm.toFullString());
      $('#jiuxingt').html(jiuxingt.toFullString());      
      $('#jiuxing-song').html(jiuxing.getSongInTaiYi());
      $('#jiuxing-songy').html(jiuxingy.getSongInTaiYi());
      $('#jiuxing-songm').html(jiuxingm.getSongInTaiYi());
      $('#jiuxing-songt').html(jiuxingt.getSongInTaiYi());      
      $('#xun').html('年空'+d.getYearXunKong()+'  月空'+d.getMonthXunKong()+'  日空'+d.getDayXunKong());

      var shuJiu = d.getShuJiu();
      $('#shuJiu').html(shuJiu ? shuJiu.toFullString() :+ '');
      
      var fu = d.getFu();
      $('#fu').html(fu ? fu.toFullString() : '');
      
      // 物候
      $('#wuhou').html(d.getHou() + '，' +d.getWuHou());      
      // 六曜
      $('#liuyao').html(d.getLiuYao());
      // 日禄
      $('#rilu').html(d.getDayLu());
      
      var lunarYear = LunarYear.fromYear(d.getYear());
      //三元九运
      $('#syjy').html(lunarYear.getYuan() + ' ' + lunarYear.getYun());
      // 治水
      $('#zhishui').html(lunarYear.getZhiShui());
      // 分饼
      $('#fenbing').html(lunarYear.getFenBing());
      // 耕田
      $('#gengtian').html(lunarYear.getGengTian());
      // 得金
      $('#dejin').html(lunarYear.getDeJin()); 
	  
      renderTime(year,month,day);
    }catch(e){
      console.log(e);
    }
  };

  compute();

  $('#year').on('input propertychange',onChange);
  $('#month').on('input propertychange',onChange);
  $('#day').on('input propertychange',onChange);
})();
</script>
</body>
</html>